package com.itjob.scott.language.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.itjob.scott.language.entity.LanguageEntity;
import com.itjob.scott.language.service.LanguageService;


//进入注册页面之前调用的方法   在index.jsp中有1个注册页面的链接
public class PreRegisterServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	private WebApplicationContext ctx = null;
	
	private LanguageService service=null;

	@Override
	public void init(ServletConfig config) throws ServletException {
		ServletContext application = config.getServletContext();
		ctx = WebApplicationContextUtils.getWebApplicationContext(application);
		service = ctx.getBean(LanguageService.class);
	}
	
	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		List<LanguageEntity> languageEntities = service.queryAll();
		request.setAttribute("languageEntities", languageEntities);
		request.getRequestDispatcher("/register.jsp").forward(request, response);
		
	}

}
